package kafkaStudy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.kafka.core.KafkaTemplate;  

import org.springframework.stereotype.Component;  

/** 
* @author 朱宏亮
* @version 创建时间：2017年12月17日 下午2:15:26 
* 类说明 kafka_2.11-1.0.0整合spring4.3.13 发布者
*/

@Component("KafkaProducerTest")
public class KafkaProducerTest {
	
	 @Autowired  
	 private KafkaTemplate<Integer, String> kafkaTemplate;  
	 
	 
	 public void testTemplateSend(Integer i){  
	 	kafkaTemplate.sendDefault(i, "你好，小宝贝:"+i);  
	 	System.out.println("执行"+i);
	 }
	 
	 @SuppressWarnings("resource")
	 public static void main(String[] args){
		ApplicationContext factory = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
		KafkaProducerTest producer = (KafkaProducerTest) factory.getBean("KafkaProducerTest");
		for(int i =0; i<10; i++){
			producer.testTemplateSend(i);
			System.out.println("send："+i);
		}
		System.out.println("send end!");
	 }
}
